var express = require("express");
var router = express.Router();
const messageApi = require("../api/message.js")
//获取
router.get("/", async function (req, res, next) {
  const data = await messageApi.getmessage();
  res.send(data);

});
//通过条件查找
router.get("/search", async function (req, res, next) {
  const find = req.query;
  // console.log('quequeqeu====>::', req.query);
  const data = await messageApi.search(find);
  res.send(data);

});


//添加
router.post("/add", async function (req, res, next) {
  const message = req.body
  console.log('message========>', message);
  const data = await messageApi.addlist(message);
  res.send(data);
});

//删除
router.delete(`/delete/:_id`, async function (req, res, next) {
  console.log(2);
  const { _id } = req.params;
  await messageApi.delete(_id);
  res.send("")
});
module.exports = router;